package com.itheima.service.impl;

import com.itheima.dao.ITeacherDao;
import com.itheima.domain.Teacher;
import com.itheima.factory.Factory;
import com.itheima.service.ITeacherService;

import java.util.ArrayList;

public class TeacherServiceImpl implements ITeacherService {
    private ITeacherDao TeacherDao = Factory.getTeacherDao();

    @Override
    public void addTeacher(Teacher Teacher) {
        TeacherDao.addTeacher(Teacher);
    }

    @Override
    public void deleteTeacher(String sid) {
        TeacherDao.deleteTeacher(sid);
    }

    @Override
    public void updateTeacher(String sid, Teacher newStu) {
        TeacherDao.updateTeacher(sid, newStu);
    }

    @Override
    public ArrayList<Teacher> findAllTeachers() {
        return TeacherDao.findAllTeachers();
    }

    @Override
    public boolean isExists(String sid) {
        ArrayList<Teacher> list = TeacherDao.findAllTeachers();
        for (int i = 0; i < list.size(); i++) {
            Teacher Teacher = list.get(i);
            if (Teacher.getSid().equals(sid)) {
                return true;
            }
        }
        return false;
    }
}